package com.smart.daotest;

import com.smart.dao.Calenderdao;
import com.smart.domain.Calender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;

import java.util.Date;

@ContextConfiguration("classpath*:/Room-context.xml")

@Rollback(false)
public class Testcalender extends AbstractTransactionalTestNGSpringContextTests {


    @Autowired
    private Calenderdao calenderdao;

    //测试添加整条元组，user_term是主码，多次添加时不可重复，且要注意Date型实际值为year+1900,month+1;
    @Test
    public void testaddcal(){
        Calender calender =new Calender();
        Date date1 =new Date(119,2,7);
        Date date2 =new Date(119,6,7);
        calender.setTerm(3);
        calender.setWeek(18);
        calender.setStartday(date1);
        calender.setStopday(date2);
        calenderdao.addcalender(calender);
    }

    //测试更新数据，下面只是举例一种情况，满足条件user_term=1的将周次改为改为18，开始结束时间均改，修改失败的情况可能是不存在满足条件的
    @Test
    public void testupdatecal(){

        Calender calender =new Calender();
        calender.setTerm(3);
        calender.setWeek(18);
        Date date1 =new Date(116,9,03);
        Date date2 =new Date(117,2,26);

        calender.setStartday(date1);
        calender.setStopday(date2);
        int a=calenderdao.updatecalender(calender);
        if(a>0)
            System.out.print("修改成功");
        else
            System.out.print("修改失败");
    }

    //删除满足条件user_term=1,并且user_weeks=18的记录
     @Test
    public  void testdeletecal(){
         Calender calender=new Calender();
         calender.setTerm(1);
         calender.setWeek(18);
         int a=calenderdao.deletecalender(calender);
         if(a>0)
             System.out.print("删除成功");
         else
             System.out.print("删除失败");
     }

     //查询表中满足user_weeks=18的记录
        @Test
    public  void testquerycal(){
            Calender calender =new Calender();
            calender.setWeek(18);
            calenderdao.querycalender(calender);
        }

        //查询表中的各个记录
        @Test
    public  void testquerycallist(){
            calenderdao.querycalenderlist();
        }

}
